package com.itheima.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.Book;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.crypto.spec.PSource;

@SpringBootTest
public class BookServiceTestCase {
//    @Autowired
//    private BookService bookService;
//
//    @Test
//    void testGetById(){
//        //System.out.println(bookService.getById(4));
//        bookService.getById(4);
//    }
//
//    @Test
//    void testSave(){
//        Book book = new Book();
//        book.setType("动画");
//        book.setName("喜羊羊与灰太狼");
//        book.setDescription("动画片");
//        bookService.save(book);
//    }
//
//    @Test
//    void testUpdate(){
//        Book book = new Book();
//        book.setId(7);
//        book.setType("电影");
//        book.setName("熊出没");
//        book.setDescription("动画片");
//        bookService.update(book);
//    }
//
//    @Test
//    void testDelete(){
//        bookService.delete(3);
//    }
//
//    @Test
//    void testGetAll(){
//        bookService.getAll();
//    }
//
//    @Test
//    void testGetPage(){
//        IPage page = bookService.getPage(2,5);
//        System.out.println(page.getTotal()); // 11
//        System.out.println(page.getPages()); //11条记录 --> 3页
//    }

    @Autowired
    private IBookService bookService;

    @Test
    void testGetById(){
        //System.out.println(bookService.getById(4));
        bookService.getById(4);
    }

    @Test
    void testSave(){
        Book book = new Book();
        book.setType("动画");
        book.setName("喜羊羊与灰太狼");
        book.setDescription("动画片");
        bookService.save(book);
    }

    @Test
    void testUpdate(){
        Book book = new Book();
        book.setId(7);
        book.setType("电影");
        book.setName("熊出没");
        book.setDescription("动画片");
        bookService.updateById(book);
    }

    @Test
    void testDelete(){
        bookService.removeById(3);
    }

    @Test
    void testGetAll(){
        bookService.list();
    }

    @Test
    void testGetPage(){
        IPage page = new Page<Book>(2,5);
        bookService.page(page);
        System.out.println(page.getTotal()); // 11
        System.out.println(page.getPages()); //11条记录 --> 3页
    }

}
